﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using System.Data;

namespace Catering.UserTraining.SlrCompanyTrainning
{
    public partial class cpntraining_nodes_register : UserIsNull
    {
        public int m_LessonID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            m_LessonID = CommRequest.GetInt("LessonID", 0);
            if (!IsPostBack)
            {
                this.LoadRep();
            }
        }

        //绑定Rep控件
        public void LoadRep()
        {
            this.Label1.Text = new Catering_Rules.StaffLessons().GetModel(m_LessonID).LessonName;
            DataTable dt_List = new Catering_Rules.NodesLessons().GetNothingNodesList(m_LessonID).Tables[0];
            this.cbl_Nothing.DataSource = dt_List;
            this.cbl_Nothing.DataTextField = "NodeName";
            this.cbl_Nothing.DataValueField = "NodeID";
            this.cbl_Nothing.DataBind();
            dt_List = new Catering_Rules.NodesLessons().GetLessonNodesList(m_LessonID).Tables[0];
            this.cbl_Nodes.DataSource = dt_List;
            this.cbl_Nodes.DataTextField = "NodeName";
            this.cbl_Nodes.DataValueField = "NodeID";
            this.cbl_Nodes.DataBind();
        }

        protected void btn_Right_Click(object sender, EventArgs e)
        {
            foreach (ListItem item in this.cbl_Nothing.Items)
            {
                if (!item.Selected) continue;
                Catering_Model.NodesLessons _TempModel = new Catering_Model.NodesLessons();
                _TempModel.LessonID = m_LessonID;
                _TempModel.NodeID = int.Parse(item.Value);
                _TempModel.AddUserID = int.Parse(Session["UserID"].ToString());
                _TempModel.AddTime = DateTime.Now;
                new Catering_Rules.NodesLessons().Add(_TempModel);
            }
            LoadRep();
        }

        protected void btn_Left_Click(object sender, EventArgs e)
        {
            foreach (ListItem item in this.cbl_Nodes.Items)
            {
                if (!item.Selected) continue;
                new Catering_Rules.NodesLessons().Delete(m_LessonID, int.Parse(item.Value));
            }
            LoadRep();
        }

        protected void btn_ReturnIndex_Click(object sender, EventArgs e)
        {
            string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_lessons_list.aspx";
            Response.Redirect(url);
        }
    }
}